package com.shaomengjie.smjmvp.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import com.shaomengjie.smjmvp.widget.color.RandomColor;

/**
 * Created by shaomengjie on 2017/5/17.
 */

public class Ball extends View {
    private int Height;
    private int Width;
    private Paint paint;
    public Ball(Context context) {
        super(context);
    }

    public Ball(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public Ball(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        int measuredHeight = getMeasuredHeight();
        int measuredWidth = getMeasuredWidth();
        this.Height = measuredHeight;
        this.Width = measuredWidth;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        paint = new Paint();
        paint.setColor(getRandomColor());
        canvas.drawCircle(Height/2,Width/2,Height/2f, paint);
    }
    public void setPaintColor(){
        paint.setColor(getRandomColor());
        invalidate();
    }
    public int getRandomColor() {
        RandomColor randomColor = new RandomColor();
        int color = randomColor.randomColor();
        return color;
    }
}
